package org.six11.ss.client;

import org.six11.ss.client.olive.OliveDrawingSurface;
import org.six11.ss.client.olive.OliveState;
import org.six11.ss.shared.Message;
import org.six11.util.adt.MultiState;

/**
 * 
 * 
 * @author Gabe Johnson <johnsogg@cmu.edu>
 */
public class RoleMessageHandler extends AWTMessageHandler {

  /**
   * @param state
   */
  protected RoleMessageHandler(MultiState state) {
    super(state);
  }

  /**
   * 
   */
  @Override
  public void handleAWT(Message msg) {

    String sketcherID = msg.getParam("sketcherID");
    String sketcherNick = msg.getParam("sketcherNick");
    OliveDrawingSurface surface = (OliveDrawingSurface) state
        .getValue(ClientStateNames.K_OLIVE_SURFACE);

    if (sketcherID.equals(state.getString(ClientStateNames.K_MY_ID))) {
      state.setValue(ClientStateNames.K_ROLE, "sketcher");
      getConsole().addStatus("YOU are going to sketch the next round!");
      bug("Enabling pen surface.");
      surface.setPenEnabled(true);
    } else {
      state.setValue(ClientStateNames.K_ROLE, "labeler");
      getConsole().addStatus(sketcherNick + " is going to sketch next!");
      bug("Disabling pen surface.");
      surface.setPenEnabled(false);
    }
  }

}
